package com.example.demo13_persistentrememberme.config;

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices;

import javax.servlet.http.HttpServletRequest;

/**
 * 自定义 TokenBasedRememberMeServices，允许通过 request.getParameter 获取令牌
 */
public class MyBaseRememberMeServices extends TokenBasedRememberMeServices {

    public MyBaseRememberMeServices(String key, UserDetailsService userDetailsService) {
        super(key, userDetailsService);
    }

    @Override
    protected String extractRememberMeCookie(HttpServletRequest request) {
        String parameter = request.getParameter(this.getCookieName());
        if (parameter == null || parameter.trim().length() == 0){
            return super.extractRememberMeCookie(request);
        }
        return parameter;
    }
}
